<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

	<link href="resources/js/selectJs/select2.css" rel="stylesheet"/>
	<script src="resources/js/selectJs/select2.js"></script>
	<script src="resources/js/calendar/calendar.js"></script>
	
	<script type="text/javascript">
		window.onload = function() {
			createCalendar();
			checkReg( nowYear, nowMonth );
		};
		
		function checkReg( targetYear, targetMonth ) {
			$.ajax({
				type: "post",
				url: "./getRegistedDays.ga",
				data: {year: targetYear, month: targetMonth},
				success: function( data ) {
					var registedDays = data.split( "/" );
					for ( var i = 0; i < registedDays.length; i++ ) {
						var day = registedDays[i].split( "|" );
						var daysCount = day[1].split( "," );
						
						if ( $("input:checkbox[value="+ targetYear + "-" + targetMonth + "-" + day[0] +"]").parent( "td" ).find( "div" ).attr( "id" ) == "daysCount" ) {
							$("input:checkbox[value="+ targetYear + "-" + targetMonth + "-" + day[0] +"]").parent( "td" ).find( "div[id=daysCount]" ).html( daysCount.length + "건" );
							$("input:checkbox[value="+ targetYear + "-" + targetMonth + "-" + day[0] +"]").parent( "td" ).find( "div[id=daysCount]" ).attr(
								"style",
								"font-size:9pt;color:#dd7733;text-align:right;height:30px;text-decoration:underline;cursor:pointer;"
							);
						} else {
							var count = $( "<div/>", {
								"id": "daysCount",
								html: daysCount.length + "건",
								"style": "font-size:9pt;color:#dd7733;text-align:right;height:30px;text-decoration:underline;cursor:pointer;"
							});
							$("input:checkbox[value="+ targetYear + "-" + targetMonth + "-" + day[0] +"]").parent( "td" ).append( count );
						}
					}
					//클릭시 예약정보 팝업!
					$("div[id=daysCount]").click( function() {
						var fullDay = $(this).parent( "td" ).children( "input:checkbox" ).val();
						var splitStr = fullDay.split( "-" );
						window.open( "./registedListPopup.ga?year=" + targetYear + "&month=" + targetMonth + "&day=" + splitStr[2], "ad", "scrollbars=yes,status=no,resizable=no,width=550,height=500" );
					});
				},
				error: function() {
					alert( "오류" );
				}
			});
		}
		
		function selectAd() {
			var coId = $("input[name=co_id]").val();
			window.open('./selectAdPopup.ga?co_id=' + coId, 'ad', 'scrollbars=yes,status=no,resizable=no,width=440,height=300');
		}
		
		function checkInput() {
			var chks = $("input[name=days]:checked");
			if( $("input[name=co_id]").val() == "" ) {
				alert("광고주를 선택하세요.");
				return false;
			} else if ( $("input[name=contentsnum]").val() == "" ) {
				alert("광고를 선택하세요.");
				return false;
			} else if ( $("input[name=promisepv]").val() == "" ) {
				alert("보장 노출 수를 입력하세요.");
				return false;
			} else if ( chks.length <= 0 ) {
				alert("날짜를 하나 이상 선택하세요.");
				return false;
			}
		}
	</script>

</head>
<body>
	<h2>꽁모으기 신규 등록 - 날짜 선택</h2>
	<form action="regGgong2.ga" method="post" onsubmit="return checkInput()">
	<table width="450px" bgcolor="#eeeeee">
		<tr>
			<td width="20%">광고주 선택</td>
			<td width="30%">
				<input type="button" value="선택"
					onclick="window.open('./selectAdvPopup.ga', 'ad', 'scrollbars=yes,status=no,resizable=no,width=440,height=300')"
				/>
			</td>
			<td>
				<input id="coname_lb" type="text" style="width:200px;" disabled/>
				<input type="hidden" name="co_id" />
			</td>
		</tr>
		<tr>
			<td>광고 선택</td>
			<td>
				<input type="button" value="선택"
					id="selectAdBtn"
					onclick="selectAd()"
					disabled
				/>
			</td>
			<td>
				<input id="contents_lb" type="text" style="width:200px;" disabled/>
				<input type="hidden" name="contents_no"/>
			</td>
		</tr>
	</table>
	<br/>
	
	■ 보장 노출 수: &nbsp; 
	<input type="text" name="promisepv"/>건
	
	<br/><br/>
	선택하시고자 하는 날짜를 선택하세요. - 다중 선택이 가능합니다.
	<br/><br/>
	
	<div id="calendar"></div>
	
	<br/>
	
	<table width="100%">
		<tr>
			<td align="right">
				<input type="submit" value="다음 ▶" style="width:120px;"/>
			</td>
		</tr>
	</table>
	
	</form>
	
</body>
</html>